package org.luxor.schedule.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.luxor.commons.core.web.controller.BaseRestController;
import org.luxor.commons.core.web.data.R;
import org.luxor.commons.jdbc.metadata.PageQuery;
import org.luxor.commons.schedule.entity.ScheduleJobLogEntity;
import org.luxor.schedule.service.impl.ScheduleJobLogServiceImpl;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * 定时任务日志
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.2.0 2016-11-28
 */
@Api(tags = "Schedule定时任务日志")
@RestController
@RequestMapping("/sys/schedule/log")
public class ScheduleJobLogController extends BaseRestController {

    @Resource
    private ScheduleJobLogServiceImpl scheduleJobLogService;

    /**
     * 定时任务日志列表
     */
    @PostMapping("/list")
    @PreAuthorize("hasPermission(#request,'sys:schedule:log:list')")
    @ApiOperation("定时任务日志列表")
    public R<IPage<ScheduleJobLogEntity>> list(@RequestBody PageQuery<HashMap> searchPage) {
        IPage<ScheduleJobLogEntity> data = scheduleJobLogService.page(searchPage.getPage(), searchPage.getSearch());
        return R.ok(data);
    }

    /**
     * 定时任务日志信息
     */
    @GetMapping("/info/{logId}")
    @PreAuthorize("hasPermission(#request,'sys:schedule:log:info')")
    @ApiOperation("定时任务日志信息")
    public R<ScheduleJobLogEntity> info(@PathVariable("logId") Long logId) {
        ScheduleJobLogEntity log = scheduleJobLogService.getById(logId);
        return R.ok(log);
    }
}
